package cn.xscrum.demo.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import cn.xscrum.common.annotation.Log;
import cn.xscrum.common.enums.BusinessType;
import cn.xscrum.demo.domain.UseRate;
import cn.xscrum.demo.service.IUseRateService;
import cn.xscrum.common.core.controller.BaseController;
import cn.xscrum.common.core.domain.AjaxResult;
import cn.xscrum.common.utils.poi.ExcelUtil;
import cn.xscrum.common.core.page.TableDataInfo;

/**
 * 不同共线站数乘客乘坐地铁比例Controller
 * 
 * @author cyb
 * @date 2020-11-25
 */
@Controller
@RequestMapping("/demo/userate")
public class UseRateController extends BaseController
{
    private String prefix = "demo/userate";

    @Autowired
    private IUseRateService useRateService;

    @RequiresPermissions("demo:userate:view")
    @GetMapping()
    public String userate()
    {
        return prefix + "/userate";
    }

    /**
	 * 查询不同共线站数乘客乘坐地铁比例列表
     */
    @RequiresPermissions("demo:userate:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(UseRate useRate)
    {
        startPage();
        List<UseRate> list = useRateService.selectUseRateList(useRate);
        return getDataTable(list);
    }

    /**
	 * 导出不同共线站数乘客乘坐地铁比例列表
     */
    @RequiresPermissions("demo:userate:export")
    @Log(title = "不同共线站数乘客乘坐地铁比例", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(UseRate useRate)
    {
        List<UseRate> list = useRateService.selectUseRateList(useRate);
        ExcelUtil<UseRate> util = new ExcelUtil<UseRate>(UseRate.class);
        return util.exportExcel(list, "userate");
    }

    /**
	 * 新增不同共线站数乘客乘坐地铁比例
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
	 * 新增保存不同共线站数乘客乘坐地铁比例
     */
    @RequiresPermissions("demo:userate:add")
    @Log(title = "不同共线站数乘客乘坐地铁比例", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(UseRate useRate)
    {
        return toAjax(useRateService.insertUseRate(useRate));
    }

    /**
	 * 修改不同共线站数乘客乘坐地铁比例
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        UseRate useRate = useRateService.selectUseRateById(id);
        mmap.put("useRate", useRate);
        return prefix + "/edit";
    }

    /**
	 * 修改保存不同共线站数乘客乘坐地铁比例
     */
    @RequiresPermissions("demo:userate:edit")
    @Log(title = "不同共线站数乘客乘坐地铁比例", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(UseRate useRate)
    {
        return toAjax(useRateService.updateUseRate(useRate));
    }

    /**
	 * 删除不同共线站数乘客乘坐地铁比例
     */
    @RequiresPermissions("demo:userate:remove")
    @Log(title = "不同共线站数乘客乘坐地铁比例", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(useRateService.deleteUseRateByIds(ids));
    }
}
